package com.mujin.keji.collectionsystem.module.sign.respository;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.mujin.keji.collectionsystem.base.BaseDto;
import com.mujin.keji.collectionsystem.base.CommonRepository;
import com.mujin.keji.collectionsystem.db.dao.SignDao;
import com.mujin.keji.collectionsystem.db.database.AppDataBase;
import com.mujin.keji.collectionsystem.db.domain.SignBean;
import com.mujin.keji.collectionsystem.module.sign.dto.SignDto;
import com.mujin.keji.collectionsystem.module.sign.vo.SignVo;


/**
 * 签到Repository
 *
 * @author weishixiong
 * @Time 2018-04-28
 */
public class SignRepository extends CommonRepository<SignDto> implements ISignRepository {
    /**
     * 签到接口
     *
     * @param vo
     */
    @Override
    public LiveData<BaseDto<SignDto>> sign(SignVo vo, Context context) {

        SignDao signDao = AppDataBase.getInstance(context).getSignDao();

        String json = JSONObject.toJSONString(vo);

        SignBean signBean = JSONObject.parseObject(json,SignBean.class);

        signDao.addSign(signBean);

        MutableLiveData data = new MutableLiveData();
        BaseDto baseDto = new BaseDto(new Object());

        data.setValue(baseDto);

        return data;
    }
}
